<?php

use app\http\middleware\Auth;
use think\facade\Route;

// 仪表盘模块
Route::group('dashboard', [
    'sps' => 'singleProductSalesChart',
    'cs' => 'categorySalesChart',
    'psds' => 'pastSevenDaysSalesChart'
])->prefix('index/DashboardCtl/')->allowCrossDomain();

// 分类模块
Route::group('classification', [
    'gfc' => 'getFirCla',
    'gsc' => 'getSecCla'
])->prefix('index/ClassificationCtl/')->allowCrossDomain();
Route::group('classification', function () {
    Route::post('afc', 'addFirCla');
    Route::put('ufc', 'updFirCla');
    Route::delete('dfc', 'delFirCla');
    Route::post('asc', 'addSecCla');
    Route::put('usc', 'updSecCla');
    Route::delete('dsc', 'delSecCla');
})->prefix('index/ClassificationCtl/')
    ->middleware(Auth::class)
    ->allowCrossDomain();

// 商品模块
Route::group('goods', [
    'iff' => 'indexFirFlood',
    'isat' => 'indexSecAndThird',
    'nap' => 'newAndPromotion',
    'activity' => 'activity',
    'brand' => 'brand',
    'getGoods' => 'getGoods',
    'getGById' => 'getGoodsById',
    'searchGoods' => 'searchGoods',
    'getSkuKeyVal' => 'getSkuKeyVal'
])->prefix('index/GoodsCtl/')->allowCrossDomain();
Route::group('goods', function () {
    Route::get('ggfa', 'getGoodsForAdmin');
    Route::post('addGoods', 'addGoods');
    Route::post('addGPic', 'addGoodsPic');
    Route::post('addGSpu', 'addGoodsSpu');
    Route::delete('delGoods', 'delGoods');
    Route::delete('delGPic', 'delGoodsPic');
    Route::delete('delGSpec', 'delGoodsSpec');
    Route::put('updGInfo', 'updGoodsInfo');
    Route::put('updGSpu', 'updGoodsSpu');
})->prefix('index/GoodsCtl/')
    ->middleware(Auth::class)
    ->allowCrossDomain();

// 评论模块
Route::get('comment/getCommentSByGid', 'index/CommentCtl/getCommentsByGid')
    ->allowCrossDomain();
Route::group('comment', function () {
    Route::post('addComment', 'addComment');
    Route::delete('delComment', 'delComment');
    Route::get('getCommentsByUid', 'getCommentsByUid');
})->prefix('index/CommentCtl/')
    ->middleware(Auth::class)
    ->allowCrossDomain();

// 用户模块
Route::group('user', function () {
    Route::post('login', 'login');
    Route::post('register', 'register');
    Route::post('adminLogin', 'adminLogin');
    Route::get('getAdminInfo', 'getAdminInfo');
})->prefix('index/UserCtl/')->allowCrossDomain();
Route::group('user', function () {
    Route::post('checkOldPass', 'checkOldPass');
    Route::put('updPassword', 'updPassword');
    Route::get('getInfoById', 'getInfoById');
    Route::post('updUserInfo', 'updUserInfo');
    Route::post('addAddress', 'addAddress');
    Route::delete('delAddress', 'delAddress');
    Route::get('getAddrByUid', 'getAddressesByUid');
    Route::put('updAddress', 'updAddress');
    Route::put('setDefaultAddr', 'setDefaultAddress');
})->prefix('index/UserCtl/')
    ->middleware(Auth::class)
    ->allowCrossDomain();

// 收藏模块
Route::group('collect', function () {
    Route::post('doCollect', 'doCollect');
    Route::delete('unFavorite', 'unFavorite');
    Route::get('getCollectByUid', 'getCollectByUid');
})->prefix('index/CollectCtl/')
    ->middleware(Auth::class)
    ->allowCrossDomain();

// 购物车模块
Route::group('cart', function () {
    Route::post('addCart', 'addCart');
    Route::delete('delCart', 'delCart');
    Route::get('getCartByUid', 'getCartByUid');
    Route::put('updCart', 'updCart');
})->prefix('index/CartCtl/')
    ->middleware(Auth::class)
    ->allowCrossDomain();

// 订单模块
Route::group('order', function () {
    Route::get('getOrders', 'getOrders');
    Route::get('getSpuInfo', 'getSelectedSpuInfo');
    Route::post('addOrder', 'addOrder');
    Route::delete('delOrder', 'delOrder');
    Route::get('getOrderByUid', 'getByUid');
    Route::put('doPay', 'doPay');
    Route::put('doDelivery', 'doDelivery');
    Route::get('getLogisticsCompany', 'getLogisticsCompany');
})->prefix('index/OrderCtl/')
    ->middleware(Auth::class)
    ->allowCrossDomain();
